package com.qqaq.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.qqaq.entities.CommonResponse;
import com.qqaq.handle.CustomerBlockHandle;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class RateLimitController
{
    @GetMapping("/byResource")
    @SentinelResource(value = "byResource",blockHandler = "handleException")
    public CommonResponse byResource()
    {
        return new CommonResponse(200,"按资源名称限流测试OK", "hahaha");
    }
    public CommonResponse handleException(BlockException exception)
    {
        return new CommonResponse(444,exception.getClass().getCanonicalName()+"\t 服务不可用");
    }

    @GetMapping("/rateLimit/customerBlockHandler")
    @SentinelResource(value = "customerBlockHandler", blockHandlerClass = CustomerBlockHandle.class, blockHandler = "handleException")
    public CommonResponse customerBlockHandler(){
        return new CommonResponse(200, "按客户自定义限流处理逻辑");
    }

}


